package com.smart.convert;

import com.smart.helper.CommonUtil;
import com.smart.model.excel.SuperviseManageHotWorkExcelVO;
import com.smart.model.vo.ProjectVO;
import org.springframework.util.ObjectUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author macbook
 */
public class SuperviseManageHotWorkExcelVOConvert {

    public static List<SuperviseManageHotWorkExcelVO> convert(List<ProjectVO> projectList) {
        return projectList.stream().map(p -> {
            Date startDate = p.getStartDate();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");
            String format = null;
            if (!ObjectUtils.isEmpty(startDate)) {
                format = simpleDateFormat.format(startDate);
            }

            String streetName = Optional.ofNullable(CommonUtil.streetMap.get(p.getStreetCode())).orElse(null);
            String engineeringType = Optional.ofNullable(CommonUtil.buildTypeMap.get(p.getEngineeringType())).orElse(null);
            String constructionStatus = Optional.ofNullable(CommonUtil.buildStatusMap.get(p.getConstructionStatus())).orElse(null);
            return SuperviseManageHotWorkExcelVO.builder()
                    .projectNumber(p.getProjectNumber())
                    .qualityRegistrationNumber(p.getQualityRegistrationNumber())
                    .projectName(p.getProjectName())
                    .street(streetName)
                    .address(p.getAddress())
                    .engineeringType(engineeringType)
                    .constructionStatus(constructionStatus)
                    .startDate(format)
                    .floorArea(!ObjectUtils.isEmpty(p.getFloorArea()) ? p.getFloorArea().toPlainString() : null)
                    .engineeringCost(!ObjectUtils.isEmpty(p.getEngineeringCost()) ? p.getEngineeringCost().toPlainString() : null)
                    .shigongUnit(p.getShigongUnit())
                    .shigongHeadName(p.getShigongHeadName())
                    .shigongHeadPhone(p.getShigongHeadPhone())
                    .shigongContactName(p.getShigongContactName())
                    .shigongContactJob(p.getShigongContactJob())
                    .shigongContactPhone(p.getShigongContactPhone())
                    .jianliUnit(p.getJianliUnit())
                    .jianliHeadName(p.getJianliHeadName())
                    .jianliHeadPhone(p.getJianliHeadPhone())
                    .jiansheUnit(p.getJiansheUnit())
                    .jiansheHeadName(p.getJiansheHeadName())
                    .jiansheHeadPhone(p.getJiansheHeadPhone()).build();
        }).collect(Collectors.toList());
    }
}
